<template>
  <div style="display: inline-block;">
    <span :class="{'weui-switch-on' : me_checked}" :value="value" class="weui-switch" @click="toggle">
      <span class="weiui-text" v-html="value ? 'ON' : 'OFF'"/>
    </span>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      me_checked: this.value
    }
  },
  watch: {
    me_checked (val) {
      this.$emit('input', val)
    },
    value (val) {
      this.me_checked = val
    }
  },
  methods: {
    toggle () {
      this.me_checked = !this.me_checked
    }
  }
}
</script>

<style scoped>
  .weui-switch {
    display: inline-block;
    position: relative;
    width: 58px;
    height: 26px;
    border: 1px solid #DFDFDF;
    outline: 0;
    border-radius: 3px;
    box-sizing: border-box;
    background-color: #DFDFDF;
    transition: background-color 0.1s, border 0.1s;
    cursor: pointer;
  }
  .weui-switch:before {
    content: " ";
    position: absolute;
    top: 0;
    left: 0;
    width: 58px;
    height: 26px;
    border-radius: 3px;
    background-color: #b4b9b5;
    transition: all 0.35s cubic-bezier(0.45, 1, 0.4, 1);
  }
  .weui-switch:after {
    content: " ";
    position: absolute;
    top: 1px;
    left: 1px;
    width: 26px;
    height: 23px;
    background-color: #FFFFFF;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: all 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35);
  }
  .weui-switch-on {
    border-color: #0bb129;
    background-color: #0bb129;
  }
  .weui-switch-on:before {
    border-color: #0bb129;
    background-color: #0bb129;
  }
  .weui-switch-on:after {
    left: 31px;
  }
  .weiui-text{
    position: relative;
    color: #d5dbd6;
    left: 30px;
    font-size: 12px;
    line-height: 26px;
  }
  .weui-switch-on>.weiui-text{
    position: relative;
    color: #fff;
    left: 5px;
    font-size: 12px;
    line-height: 26px;
  }
</style>
